package com.itboye.ihomebank.util;

import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.ttKey.Key;

/**
 * 锁数据
 */
public class SaveKeyBean {
    //绑定锁的数据，传1代表存在本地，传其他的则代表上传成功了，清空本地的数据
    public static void saveData(String type,Key key){
        if (type.equals("1")){
            SPUtils.put(MyApplcation.ctx, null,SPContants.LOCKMAC, key.getLockMac());
            SPUtils.put(MyApplcation.ctx, null,SPContants.LOCKNAME, key.getLockName());
            SPUtils.put(MyApplcation.ctx, null,SPContants.UNLOCKKEY, key.getUnlockKey());
            SPUtils.put(MyApplcation.ctx, null,SPContants.AESKEYSTER, key.getAesKeystr());
            SPUtils.put(MyApplcation.ctx, null,SPContants.LOCKVERSION, key.getLockVersion());
            SPUtils.put(MyApplcation.ctx, null,SPContants.ADMINPSS, key.getAdminPs());
            SPUtils.put(MyApplcation.ctx, null,SPContants.BATTERY, key.getBattery());
            if (key.getDeletePwd()!=null){
                SPUtils.put(MyApplcation.ctx, null,SPContants.ADMINKEYBOARPWD, key.getAdminKeyboardPwd());
            }
            if (key.getDeletePwd()!=null){
                SPUtils.put(MyApplcation.ctx, null,SPContants.DELETEPWDS, key.getDeletePwd());
            }
            if (key.getPwdInfo()!=null){
                SPUtils.put(MyApplcation.ctx, null,SPContants.PWDINGO, key.getPwdInfo());
            }
            if (key.getTimestamp()!=0){
                SPUtils.put(MyApplcation.ctx, null,SPContants.TIMESTAMP,String.valueOf(key.getTimestamp()) );
            }
            if (key.getSpecialValue()!=0){
                SPUtils.put(MyApplcation.ctx, null,SPContants.FEATURE, String.valueOf(key.getSpecialValue()));
            }
        }else{
            SPUtils.put(MyApplcation.ctx, null,SPContants.LOCKMAC,"");
            SPUtils.put(MyApplcation.ctx, null,SPContants.LOCKNAME, "");
            SPUtils.put(MyApplcation.ctx, null,SPContants.UNLOCKKEY, "");
            SPUtils.put(MyApplcation.ctx, null,SPContants.AESKEYSTER, "");
            SPUtils.put(MyApplcation.ctx, null,SPContants.LOCKVERSION, "");
            SPUtils.put(MyApplcation.ctx, null,SPContants.ADMINPSS, "");
            SPUtils.put(MyApplcation.ctx, null,SPContants.ADMINKEYBOARPWD,"");
            SPUtils.put(MyApplcation.ctx, null,SPContants.DELETEPWDS,"");
            SPUtils.put(MyApplcation.ctx, null,SPContants.PWDINGO, "");
            SPUtils.put(MyApplcation.ctx, null,SPContants.TIMESTAMP,"");
            SPUtils.put(MyApplcation.ctx, null,SPContants.FEATURE,"");
//            SPUtils.put(MyApplcation.ctx, null,SPContants.BATTERY, key.getBattery());
        }
    }
    //科技侠解绑锁的数据，如果没有网，上传没成功，存在本地；如果上传成功了   就删除
    public static void saveDataTwo(String type,Key key){
        if (type.equals("1")){
            if (key.getKeyId()!=null){
                SPUtils.put(MyApplcation.ctx, null,SPContants.J_KEYID, key.getKeyId());
            }
            if (key.getLockId()!=null){
                SPUtils.put(MyApplcation.ctx, null,SPContants.J_LOCKID, key.getLockId());
            }
            if (key.getAesKeystr()!=null){
                SPUtils.put(MyApplcation.ctx, null,SPContants.AESKEYSTR, key.getAesKeystr());
            }
        }else{
            SPUtils.put(MyApplcation.ctx, null,SPContants.J_KEYID,"");
            SPUtils.put(MyApplcation.ctx, null,SPContants.J_LOCKID, "");
            SPUtils.put(MyApplcation.ctx, null,SPContants.AESKEYSTR, "");
        }
    }

}
